package com.hcbd.tdwt.ui.xingyu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.hcbd.tdwt.R;
import com.hcbd.tdwt.base.bd.BdToolFactory;
import com.amap.api.maps.AMap;
import com.amap.api.maps.model.Marker;


import com.hcbd.tdwt.util.StringUtil;
import com.hcbd.tdwt.ui.xingyu.vo.BoxContact;

import java.text.DecimalFormat;
import java.text.MessageFormat;

/**
 * - @Description:  高德地图标志弹框
 * - @Author:  LXJ
 * - @Time:  2019/6/24 17:02
 */
public class AmapInfoWinAdapter implements AMap.InfoWindowAdapter {
   private Context mContext;
    private TextView timeTv;
    private TextView longitudeTv;
    private TextView latitudeTv;
    private TextView cardNumTv;
    private TextView sendMsgTv,detailsTv;

   public  AmapInfoWinAdapter(Context context){
       this.mContext=context;
   }
    public void setInfoWindowViewInterface(InfoWindowViewInterface linsner){
        this.windowViewInterface = linsner;
    }

    @Override
    public View getInfoWindow(Marker marker) {

        View view = initView(marker);
        return view;
    }

    @Override
    public View getInfoContents(Marker marker) {
        return null;
    }

    public static Info build(BoxContact boxContact){
        Info info=new Info();
        info.latitude= StringUtil.stringToDouble(boxContact.getLatitude());
        info.longitude=StringUtil.stringToDouble(boxContact.getLongitude());
        info.number=boxContact.getBoxId();
        info.timer=boxContact.getRecentCommunicationTime();
       return info;
    }

    private InfoWindowViewInterface windowViewInterface;
    public void setBgStyle(){

    }
    private View initView(final Marker marker) {
        DecimalFormat df = new DecimalFormat("0.000000");

        Info info = (Info)marker.getObject();
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_info_window, null);
        cardNumTv=view.findViewById(R.id.cardNumTv);
        longitudeTv=view.findViewById(R.id.longitudeTv);
        latitudeTv=view.findViewById(R.id.latitudeTv);
        timeTv=view.findViewById(R.id.timeTv);
        sendMsgTv=view.findViewById(R.id.sendMsgTv);
        detailsTv=view.findViewById(R.id.detailsTv);
        if(BdToolFactory.app_type==BdToolFactory.FU_DA_BG_TYPE){
            view.setBackground(mContext.getDrawable(R.color.white));
            cardNumTv.setTextColor(mContext.getColor(R.color.black));
            longitudeTv.setTextColor(mContext.getColor(R.color.black));
            latitudeTv.setTextColor(mContext.getColor(R.color.black));
            timeTv.setTextColor(mContext.getColor(R.color.black));
        }
        cardNumTv.setText(MessageFormat.format("卡号: {0}", info.number));
        longitudeTv.setText(MessageFormat.format("经度: {0}",df.format(info.longitude)));
        latitudeTv.setText(MessageFormat.format("纬度: {0}", df.format(info.latitude)));
        timeTv.setText(MessageFormat.format("定位时间: {0}", info.timer));
        sendMsgTv.setOnClickListener(view1 -> windowViewInterface.onSendMsg(info.number));
        detailsTv.setOnClickListener(view12 -> windowViewInterface.onDetails(info));
        return view;
    }
    public static class Info {
        public String number;
        public double longitude;
        public double latitude;
        public String timer;
    }
    public interface InfoWindowViewInterface {
          void onSendMsg(String number);
          void onDetails(Info info);
    }
}
